package org.jeecg.modules.xl.order.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.query.QueryRuleEnum;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.xl.order.entity.XlCustomerOrde;
import org.jeecg.modules.xl.order.service.IXlCustomerOrdeService;
import org.jeecg.modules.xl.order.service.IXlCustomerOrderDetailService;
import org.jeecg.modules.xl.order.utils.DictUtils;
import org.jeecg.modules.xl.store.service.IXlCustomerMystoreService;
import org.jeecg.modules.xl.store.service.IXlCustomerStoreInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 订单创建菜单上的控制器
 *
 * @author deco
 * @create 2025-03-11
 */
@RestController
@RequestMapping("/htm/ordercreate")
@Slf4j
public class OrderCreateController {
    @Autowired
    private IXlCustomerOrdeService xlCustomerOrdeService;
    @Autowired
    private IXlCustomerOrderDetailService xlCustomerOrderDetailService;


    @Autowired
    private DictUtils dictUtils;

    @Autowired
    private IXlCustomerStoreInfoService xlCustomerStoreInfoService;

    @Autowired
    private IXlCustomerMystoreService xlCustomerMystoreService;
    @GetMapping(value = "/list")
    public Result<IPage<XlCustomerOrde>> queryPageList(XlCustomerOrde xlCustomerOrde,
                                                       @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                       @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                       HttpServletRequest req) {
        // 自定义查询规则
        Map<String, QueryRuleEnum> customeRuleMap = new HashMap<>();
        // 自定义多选的查询规则为：LIKE_WITH_OR
        customeRuleMap.put("storeCode", QueryRuleEnum.LIKE_WITH_OR);
        QueryWrapper<XlCustomerOrde> queryWrapper = QueryGenerator.initQueryWrapper(xlCustomerOrde, req.getParameterMap(),customeRuleMap);
        Page<XlCustomerOrde> page = new Page<XlCustomerOrde>(pageNo, pageSize);

        int ShengHeZhong_Kuaidi = 1;//审核中-快递订单
        int YiShenHe = 2;//已审核
        int Zhifupinzhengtijiao = 3;//支付凭证提交
        int FaHuoZhongPage = 6;//发货中



        //当前操作人
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        //当前用户的角色
        String roles = user.getRoleCode();

        //是否管理员角色
//		if (!StrUtil.containsAny(roles, CommonConstant.ADMIN_ROLES)) {
        if (StrUtil.containsAny(roles, "slt_customer")) {//是否是采购人员
            queryWrapper.lambda()
                    //筛选自己创建的
                    .and(e-> e.eq(XlCustomerOrde::getCreateBy, user.getUsername())
                    );
        }
        IPage<XlCustomerOrde> pageList = xlCustomerOrdeService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

}
